<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
if($_RQ['op']=='get'){
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','username','nickname'));
	$tips='请提交真实姓名，身份证号码！以备顺利完成绑卡申请！';
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($_RQ['tid']){
		$payplog=pdo_get('core_paylog',array('tid'=>$_RQ['tid'],'uniacid'=>$_SESSION['uniacid']));
		$params['merchid']=$payplog['merchid'];
	}
	$item=pdo_get('jy_allinpay_log',$params);
	$item['nickname']=$$member['nickname']?:$member['username'];
	if($_RQ['tid']){
		$item['tid']=$_RQ['tid'];
		$item['merchid']=$payplog['merchid'];
	}
	$return['item']=$item;
	$return['tips']=$tips;
	set_html('title','绑卡申请');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$postdata['ordersn']='SN'.get_ordersn($this->tablename('log'),'ordersn');
	if(!$postdata['realname'] || !$postdata['cardnum'] || !$postdata['mobile'] || !$postdata['acctno']){
		exi('姓名，身份证号，手机号，银行卡号必填！','error');
	}
	$postdata['id']=$postdata['id']?:$this->model('model')->addlog($postdata);
	$res=$this->model('model')->checkinfo($postdata);
	if($res['thpinfo']){
		$res['logid']=$postdata['id'];
		exi($res);
	}else{
		$this->pdo_update('log',array('agreeid'=>$res['agreeid'],'passed'=>1,'response_data'=>ijson_encode($res)),array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['id']));
		if($postdata['tid']){
			$payplog=pdo_get('core_paylog',array('tid'=>$postdata['tid'],'uniacid'=>$_SESSION['uniacid']));
			$payplog['agreeid']=$res['agreeid'];
			if(!$payplog['status']){
				$this->model('model')->payapplyagree($payplog);
			}
		}else{
			exi('签约成功！','',$_SESSION['forward_url']);
		}
	}
}
if($_RQ['op']=='getsmspost'){
	$postdata=get_postdata();
	if(!$postdata['realname'] || !$postdata['cardnum'] || !$postdata['mobile'] || !$postdata['acctno']){
		exi('姓名，身份证号，手机号，银行卡号必填！','error');
	}
	$postdata['id']=$this->model('model')->addlog($postdata);
	$res=$this->model('model')->checkinfo($postdata,'',1);
	exi('获取成功！');
}
if($_RQ['op']=='checkpost'){
	$postdata=get_postdata();
	if(!$postdata['realname'] || !$postdata['cardnum'] || !$postdata['mobile'] || !$postdata['acctno']){
		exi('姓名，身份证号，手机号，银行卡号必填！','error');
	}
	if(!$postdata['smscode']){
		exi('请输入验证码！','error');
	}
	$postdata['logid']=$this->model('model')->addlog($postdata);
	$res=$this->model('model')->checkinfo($postdata,1);
	$this->pdo_update('log',array('agreeid'=>$res['agreeid'],'passed'=>1,'response_data'=>ijson_encode($res)),array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['logid']));
	$returl=pdo_getcolumn('jy_allinpay_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['logid']),'returl');
	if($postdata['tid']){
		$payplog=pdo_get('core_paylog',array('tid'=>$postdata['tid'],'uniacid'=>$_SESSION['uniacid']));
		$payplog['agreeid']=$res['agreeid'];
		if(!$payplog['status']){
			$this->model('model')->payapplyagree($payplog);
		}
	}else{
		exi('绑卡成功！','',$returl?:'jy_weishop/order.list/');
	}
}